package com.foruo.learn.designmode.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 发布者
 * @author GaoYuan
 * @date 2018/11/11 上午9:55
 */
public class Publisher {

    private List<Subscriber> subscriberList = new ArrayList<>();

    /** 发布消息 */
    public void publish(String msg){
        for(Subscriber subscriber:subscriberList){
            subscriber.answer(msg);
        }
    }

    /** 订阅 */
    public void add(Subscriber subscriber){
        subscriberList.add(subscriber);
    }
}
